<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<base href="/tpshop" />
	<title>京东(JD.COM)-综合网购首选-正品低价、品质保障、配送及时、轻松购物！</title>
	<link rel="stylesheet" href="/tpshop/Public/css/bootstrap.min.css">
	<link rel="stylesheet" href="/tpshop/Public/css/bootstrap-theme.min.css">
	<link rel="stylesheet" href="/tpshop/Public/css/front.css">
	<link rel="stylesheet" href="/tpshop/Public/css/nivo-slider.css">
	
</head>
<body>
	<div class="container">
		<div class="row" id="header" >
			<div class="col-md-3">
				<a href="/tpshop/index.php"><img id="logo" src="/tpshop/Public/img/logo.png" /></a>
			</div>
			<div class="col-sm-9">
			    <img height="50" class="pull-right" src="/tpshop/Public/img/shop_step1.jpg" />
			</div>
		</div>
		<div class="row">
			<form action="<?=U('home/shopping/do_order')?>" method="post">
			<div class="col-md-12">
			<h3>收货地址<button id="addAddress" class="btn btn-success btn-xs pull-right">添加收货地址</button></h3>
				<table class="table table-bordered">
				<?php foreach($address as $a){?>
					<tr>
						<td width="30" class="text-center">
							<input type="radio" name="address_id" value="<?=$a['id']?>" />
						</td>
						<td width="200" class="text-center">收件人：<?=$a['name']?></td>
						<td>收货地址：<?=$a['address']?></td>
						<td>联系方式：<?=$a['phone']?></td>
						<td class="text-center">
							<a href=""><i class="glyphicon glyphicon-remove-circle" style="color:#C81623;"></i></a>
						</td>
					</tr>
					<?php }?>
				</table>
				<table class="table table-bordered">
					<tr >
						<th class="text-center ">商品</th>
						<th class="text-center " width="160">价 格</th>
						<th class="text-center " width="140">数 量</th>
						<th class="text-center " width="140">总 计</th>
					</tr>
					<?php
 $sum = 0; foreach($data as $c){ $product = M('product')->where('id ='.$c['product_id'])->find(); ?>
					<tr class="t">
						<input type="hidden" name="product_id[]" value="<?=$c['product_id']?>">
						<input type="hidden" name="num[]" value="<?=$c['num']?>">
						<td><a href="<?=U('product/detail/'.$product['id'])?>">
						<img style="width:60px;" src="/tpshop<?=$product['img']?>"><?=$product['title']?></a></td>
						<td>￥<?=$product['price']?></td>
						<td class="cart_num">
							<?=$c['num']?>
						</td>
						<td>￥<?php echo $p = intval($product['price']) * intval($c['num'])?></td>
						<?php $sum = $sum + $p;?>
					</tr>
					<?php }?>
				</table>
				<button type="submit" class="btn btn-danger pull-right">提交订单</button>
				</form>
			</div>
		</div>
		<div class="modal fade" id="addressForm">
		  <div class="modal-dialog">
		    <div class="modal-content">
		      <div class="modal-header">
		        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
		        <h4 class="modal-title">添加收货地址</h4>
		      </div>
		      <div class="modal-body">
		      	<form>
		      		<div class="form-group">
				        <label>收件人</label>
						<input type="text" name="name" class="form-control" placeholder="请输入收件人姓名...">	
		      		</div>
		      		<div class="form-group">
					    <label>收货地址</label>
						<textarea name="address" class="form-control" placeholder="请输入收货地址..."></textarea>	
		      		</div>
		      		<div class="form-group">
				    	<label>联系方式</label>
						<input type="text" name="phone" class="form-control" placeholder="请输入联系方式...">	
		      		</div>
		      	</form>
		      <div class="modal-footer">
		        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
		        <button id="addressSave" type="button" class="btn btn-primary">保存</button>
		      </div>
		    </div>
		  </div>
		</div>
	</div>
	</div>
	<script type="text/javascript" src="/tpshop/Public/js/jquery-3.1.0.min.js"></script>
	<script type="text/javascript" src="/tpshop/Public/js/bootstrap.min.js"></script>
	<script type="text/javascript">
		$(function(){
			$('#addAddress').click(function(){
				$('#addressForm').modal('show');
				return false;
			})
			$('#addressSave').click(function(){
				var name = $('#addressForm input[name="name"]').val();
				var address = $('#addressForm textarea[name="address"]').val();
				var phone = $('#addressForm input[name="phone"]').val();
				$.post("<?=U('shopping/addAddress')?>",{
					name:name,
					address:address,
					phone:phone
				},function(data){
					data = eval("("+data+')');
					if(data.code == 'ok'){
						location.reload();
					}
					if(data.code == 'error'){
						$('#addressFrom [name = "'+data.field+'"]').after('<p class="error">'+data.msg+'</p>')
					}
				})
			})
		})
	</script>
</body>
</html>